package com.readpost.validation;

import com.readpost.anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class StateValidation implements ConstraintValidator<State, String> {

    /**
     * 校验状态
     *
     * @param s 要校验的值
     * @param constraintValidatorContext
     * @return false 表示校验失败，true 表示校验成功
     */
    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
       if (s == null) {
           return false;
       }
       if (s.equals("draft") || s.equals("published")) {
            return true;
       }else {
            return false;
        }
    }
}
